<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('诊疗单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            耳号：<input type="text" id="cowCode" name="cowCode"/>
                        </li>
                        <li>
                            状态：
                            <select name="zlStatus" id="zlStatus">
                                <option value="">所有</option>
                                <option value="1">待确认</option>
                                <option value="3">已确认</option>
                                <option value="4">已生成订单</option>
                                <option value="5">待发送</option>
                            </select>

                        </li>
                        <li class="select-time">
                            <label>日期： </label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginzlTime]" lay-key="1">
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endzlTime]" lay-key="2">
                        </li>

                        <!--<li>
                            备注：<input type="text" name="remark"/>
                        </li>
-->
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>




        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table-mianyi-logs-status1" data-mobile-responsive="true"></table>
        </div>

        <div id="toolbar1">
            <a class="btn btn-success" onclick="askZhenLiao()">
                <i class="fa fa-plus"></i> 新增诊疗请求
            </a>

            <a class="btn btn-warning" onclick="confirmTable();">
                <i class="fa fa-send"></i> 发送
            </a>
        </div>

    </div>
</div>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('system:ncZhenliaoLogs2:edit')}]];
    var removeFlag = [[${@permission.hasPermi('system:ncZhenliaoLogs:remove')}]];
    var prefix = ctx + "system/ncZhenliaoLogs/cow";
    var datas = [[${@dict.getType('cow_juanshe_num')}]];
    var detailFlag = [[${@permission.hasPermi('system:ncCowsZhenliaoLogs:detail')}]];

    $(function () {

        var optionsStatus1 = {
            id: "bootstrap-table-mianyi-logs-status1",
            url: prefix + "/list?zlType=1",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit2/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            detailUrl: prefix + "/detail/{id}",
            modalName: "诊疗单",
            showExport: false,
            striped: false,
            showSearch: false,
            showRefresh: false,
            showColumns: false,
            showToggle: false,
            uniqueId: "zlId",
            toolbar: 'toolbar1',
            sortName:'createTime',
            sortOrder:'desc',
            /*      confirmUrl:prefix + "/confirmTable",*/
            columns: [
                {
                    checkbox: true
                },
                {
                    title: '序号',
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field: 'zlId',
                    title: '诊疗单号',
                    visible: false
                },
                {
                    field: 'cowCode',
                    title: '耳号',

                },
                {
                    field: 'roomNum',
                    title: '圈舍号',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(datas, value);
                    }
                },
                {
                    field: 'ageDays',
                    title: '日龄',
                    sortable: true,
                    visible: false

                },
                {
                    field: 'illMuns',
                    title: '发病次数',
                    sortable: true
                },
                {
                    field: 'zlStatus',
                    title: '状态',
                    sortable: true,
                    formatter: function (value, row, index) {
                        if(value==1){
                            return "待确认"
                        }if(value==3){
                            return "已确认"
                        }if(value==4){
                            return "已生成订单"
                        }if(value==5){
                            return "待发送"
                        }
                    }
                },
                {
                    field: 'createTime',
                    title: '请求时间',
                    sortable: true
                },

                {
                    field: 'symptom',
                    title: '症状',
                    sortable: true
                },

                {
                    field: 'remark',
                    title: ' 备注',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];

                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.zlId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.zlId + '\')"><i class="fa fa-remove"></i>删除</a>');


                        return actions.join('');
                    }
                }]
        };


        $.table.init(optionsStatus1);



    });



    //新增诊疗单
    function addZhenLiaoLogs(name, url) {
        $.modal.openTab(name, url);
    }



    /*打开鸡舍诊疗记录单*/
    function openOrder() {
        var url = ctx + 'system/ncOrder?orderType=17';
        $.modal.openTab("鸡舍诊疗记录单", url);
    }




    function askZhenLiao() {
        $.modal.open("添加", "/system/ncZhenliaoLogs/cow/askZhenLiao");
    }


    //刷新页面
    function reload() {
        $.table.refresh();
    }


    /*表单确认*/
    function confirmTable() {
        var rows = $.common.isEmpty($.table._option.uniqueId) ? selectFirstColumns() : selectColumns($.table._option.uniqueId);
        console.log(rows)
        if(rows.length > 0){
            $.modal.confirm("确认要发送请求?", function () {
                var url = prefix + "/sendZlRequest";
                var data = {"ids": rows.join()};
                $.operate.submit(url, "post", "json", data);
            });
        }
        else {

            var confirmTable = prefix + "/sendZlRequest";
            var data = $('#bootstrap-table-mianyi-logs-status1').bootstrapTable('getData');
            // console.log(data)
            if (data && data.length > 0) {

                $.modal.confirm("确认发送到兽医请求吗？", function () {
                    var ids = [];
                    $(data).each(function (i, e) {

                        // console.log(e.btSelectItem)

                        ids.push(e.zlId);
                    });
                    var ids_str = ids.join(",");
                    myPost(confirmTable, {ids: ids_str},
                        function (data) {

                            if (data.code == 0) {
                                layer.msg("提交成功")
                            } else {
                                layer.msg(data.msg);
                            }
                            reload()
                        }, function (e) {
                            layer.msg("确认失败!");
                            reload()
                        })

                })
            } else {
                layer.msg("未发现数据!")
            }

        }

    }

    // 查询表格指定列值
    function selectColumns(column) {
        var rows = $.map($.btTable.bootstrapTable('getSelections'), function (row) {
            return row[column];
        });
        if ($.common.isNotEmpty($.table._option.rememberSelected) && $.table._option.rememberSelected) {
            rows = rows.concat(selectionIds);
        }
        return $.common.uniqueFn(rows);
    }

    // 查询表格首列值
    function selectFirstColumns() {
        var rows = $.map($.btTable.bootstrapTable('getSelections'), function (row) {
            return row[$.table._option.columns[1].field];
        });
        if ($.common.isNotEmpty($.table._option.rememberSelected) && $.table._option.rememberSelected) {
            rows = rows.concat(selectionIds);
        }
        return $.common.uniqueFn(rows);
    }
    setTitle("牛舍管理-兽医请求",true)
</script>
</body>
</html>